(function(){
	
// carousel
let imgs = ["../img/crs3.jpg","../img/crs4.jpg","../img/crs5.jpg","../img/crs6.jpg","../img/crs7.jpg","../img/crs8.jpg"];
function carousel(){
	this.container = document.querySelector(".carousel>div");
	this.ul = document.querySelector(".carousel>ul");
	this.j = 0;
}
carousel.prototype.init = function(){
	this.render();
	this.interval();
}
carousel.prototype.render = function(){
	this.container.style.width = 3.6*imgs.length + "rem";
	this.ul.style.width = .1*imgs.length + "rem";
	this.ul.style.marginLeft = .05*imgs.length*-1 + "rem";
	imgs.forEach((val,i)=>{
		let img = new Image();
		img.src = val;
		this.container.appendChild(img);
		let li = document.createElement("li");
		i == 0 && (li.className = "active");
		this.ul.appendChild(li);
	})
}
carousel.prototype.interval = function(){
	let me = this;
	this.timer = setInterval(function(){
		me.j == imgs.length - 1 ? (me.j = 0) : me.j++
		me.container.style.marginLeft = -3.6*me.j + "rem";
		for(let i in me.ul.children){
			me.ul.children[i].className = "";
		}
		me.ul.children[me.j].className = "active";
	},2500)
}
var crsl = new carousel();
crsl.init();


// movieList
// 模拟后台数据
let movies = [
			{"mvimg":"../img/mv1.jpg","url1":"detail.html","url2":"detail.html","ifhui":true,"name":"失控玩家","score":8.5,"describe":"当游戏NPC一夜觉醒","classes":"喜剧，动作，科幻/英语","byway":["3D","IMAX","2D"],"btn":"购票"},
			{"mvimg":"../img/mv2.jpg","url1":"detail.html","url2":"detail.html","ifhui":true,"name":"怒火·重案","score":8.9,"describe":"甑子丹谢霆锋热血警察为正义拼命","classes":"动作，犯罪/粤语","byway":["IMAX","2D"],"btn":"购票"},
			{"mvimg":"../img/mv3.jpg","url1":"detail.html","url2":"detail.html","ifhui":true,"name":"妈妈的神奇小子","score":8.7,"describe":"残奥会冠军苏华伟真人真事改编","classes":"剧情，喜剧/粤语/汉语普通话","byway":["2D"],"btn":"购票"},
			{"mvimg":"../img/mv4.jpg","url1":"detail.html","url2":"detail.html","ifhui":true,"name":"夏日友晴天","score":8.8,"describe":"无关爱情，友情也动人","classes":"喜剧，动画，奇幻，冒险/英语/意大利语","byway":["3D","2D"],"btn":"购票"},
			{"mvimg":"../img/mv5.jpg","url1":"detail.html","url2":"detail.html","ifhui":true,"name":"1950他们正年轻","score":8.7,"describe":"“不忘英雄”是对英雄最好的致敬","classes":"纪录/汉语普通话","byway":["2D"],"btn":"购票"},
			{"mvimg":"../img/mv6.jpg","url1":"detail.html","url2":"detail.html","ifhui":true,"name":"白蛇2：青蛇劫起","score":8.8,"describe":"小青直面情感考验","classes":"动画，奇幻，冒险/汉语普通话","byway":["3D","IMAX","2D"],"btn":"购票"},
			{"mvimg":"../img/mv7.jpg","url1":"detail.html","url2":"detail.html","ifhui":true,"name":"盛夏未来","score":8.4,"describe":"张子枫吴磊交换秘密共赴未来","classes":"剧情/汉语普通话","byway":["2D"],"btn":"购票"},
			{"mvimg":"../img/mv8.jpg","url1":"detail.html","url2":"detail.html","ifhui":true,"name":"地道战","score":8.8,"describe":"地道战，人民抗战的汪洋大海","classes":"战争/汉语普通话","byway":["2D"],"btn":"购票"},
			{"mvimg":"../img/mv5.jpg","url1":"detail.html","url2":"detail.html","ifhui":true,"name":"小花仙奇迹少女","score":8.3,"describe":"华丽开启魔法之旅","classes":"动画/汉语普通话","byway":["3D","2D"],"btn":"购票"},
			{"mvimg":"../img/mv1.jpg","url1":"detail.html","url2":"detail.html","ifhui":true,"name":"失控玩家","score":8.5,"describe":"当游戏NPC一夜觉醒","classes":"喜剧，动作，科幻/英语","byway":["3D","IMAX","2D"],"btn":"购票"},
			{"mvimg":"../img/mv2.jpg","url1":"detail.html","url2":"detail.html","ifhui":true,"name":"怒火·重案","score":8.9,"describe":"甑子丹谢霆锋热血警察为正义拼命","classes":"动作，犯罪/粤语","byway":["IMAX","2D"],"btn":"购票"},
			{"mvimg":"../img/mv3.jpg","url1":"detail.html","url2":"detail.html","ifhui":true,"name":"妈妈的神奇小子","score":8.7,"describe":"残奥会冠军苏华伟真人真事改编","classes":"剧情，喜剧/粤语/汉语普通话","byway":["2D"],"btn":"购票"},
			];
function moviesElement(){
	this.container = document.querySelector("section>.movieList");
}
moviesElement.prototype.init = function(){
	this.render();
}
moviesElement.prototype.render = function(){
	movies.forEach(val=>{
		let parentDiv = document.createElement("div"),
			firstChildDiv = document.createElement("div"),
			img = new Image(),
			a1 = document.createElement("a");
			img.src = val.mvimg;
			a1.href = val.url1;
			a1.target = "_blank";
			a1.appendChild(img);
			firstChildDiv.appendChild(a1);
			if(val.ifhui){
				let firstSpan = document.createElement("span");
				firstSpan.innerHTML = "惠";
				firstChildDiv.appendChild(firstSpan);
			}
			parentDiv.className = "listdetail";
			parentDiv.appendChild(firstChildDiv);
		let	lastChildDiv = document.createElement("div"),
			a2 = document.createElement("a"),
			h3 = document.createElement("h3"),
			p1 = document.createElement("p"),
			p2 = document.createElement("p"),
			p3 = document.createElement("p"),
			p4 = document.createElement("p"),
			pSpan1 = document.createElement("span");
			p1.innerText = "评分";
			pSpan1.innerHTML = val.score;
			p1.appendChild(pSpan1);
			val.byway.forEach(val=>{
				let span = document.createElement("span");
				span.innerHTML = val;
				p4.appendChild(span);
			})
			h3.innerHTML = val.name;
			p2.innerHTML = val.describe;
			p3.innerHTML = val.classes;
			a2.href = val.url1;
			a2.target = "_blank";
			a2.appendChild(h3);
			a2.appendChild(p1);
			a2.appendChild(p2);
			a2.appendChild(p3);
			a2.appendChild(p4);
			lastChildDiv.appendChild(a2);
			let btnDiv = document.createElement("div"),
				btnA = document.createElement("a");
			btnA.href = val.url2;
			btnA.target = "_blank";
			btnA.innerHTML = val.btn;
			val.btn == "购票" ? (btnA.style.background = "#00c2c3") : (btnA.style.background = "#D0BA7D");
			btnDiv.appendChild(btnA);
		lastChildDiv.appendChild(btnDiv);
		parentDiv.appendChild(lastChildDiv);
		this.container.appendChild(parentDiv);
	})
}
let addMv = new moviesElement();
addMv.init();




})()